package com.felix.collection;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * demo
 *
 * @author xjh
 * @version 1.0
 * @date 2019-03-14
 */
public class ConcurrentHashMapDemo{
    private Map<Integer,Integer> cache =new ConcurrentHashMap<>(15);

    public static void main(String[]args){
        ConcurrentHashMapDemo ch =    new ConcurrentHashMapDemo();
        System.out.println(ch.fibonacci(80));
        System.out.println(123);
    }

    public int fibonacci(Integer i){
        if(i==0||i ==1) {
            return i;
        }

        return cache.computeIfAbsent(i,key -> {
            System.out.println("fibonacci : "+key);
            return fibonacci(key -1)+fibonacci(key - 2);
        });
    }
}

